package com.frame.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.frame.domain.Permission;
import com.frame.domain.Role;
import com.mini.core.dao.MiniDao;

/**
 * DAO for {@link Permission}.
 */
@Service
public class PermissionService{
	@Autowired
	MiniDao miniDao;
	
	/**
	 * 查找所有权限
	 * @return
	 */
	public List<Permission> findAll(){
		String sql = "SELECT * FROM PERMISSION";
		return miniDao.findList(sql, Permission.class);
	}

	/**
	 * 根据roleid找相应的权限
	 * @param id
	 */
	public List<Permission> findByRoleid(String roleid) {
		return miniDao.findList("SELECT p.* FROM PERMISSION p,ROLE_PERMISSION rp WHERE p.ID=rp.PERMISSIONID AND rp.ROLEID=? AND p.PERMKEY<>?", Permission.class, roleid,"*");
	}
}
